/**
 * 17/gen/2012 - fabio.melillo@gmail.com
 */
package unisannio.fm.interactive;

import org.unisannio.remote.FactoryRemote;
import org.unisannio.remote.RemoteBroadcaster;

import unisannio.fm.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author fabio
 *
 */
public class ResponseActivity extends Activity {
	
	TextView rispostaField;
	Button reply,cancel;
	String action;
	String domanda;
	Bundle bundle;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle bundle=getIntent().getExtras();
        domanda = bundle.getString(HelpMeActivity.questionKey);
        action = bundle.getString("action");
        setContentView(R.layout.answer);
        TextView label=(TextView) findViewById(R.id.questionText);
        label.setText(domanda);
        rispostaField=(TextView) findViewById(R.id.answerField);
        reply=(Button) findViewById(R.id.reply);
        cancel=(Button) findViewById(R.id.cancel);
        
        reply.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View arg0) {
				String risposta=rispostaField.getText().toString();
				FactoryRemote factory=new FactoryRemote();
				RemoteBroadcaster remote=factory.getRemoteBroadcaster(ResponseActivity.this);
				bundle.putString(HelpMeActivity.responseKey, risposta);
				bundle.putString(HelpMeActivity.questionKey,domanda);
				remote.returnRemoteResult(action, bundle);
				ResponseActivity.this.finish();
			}
		});
        
        cancel.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ResponseActivity.this.finish();
				
			}
		});
        
    };

}
